<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>随时更新位置</title>
</head>
<body>
<!--watchPosition() - 返回用户的当前位置，并继续返回用户移动时的更新位置-->
<p id="demo">获取坐标：</p>
<button onclick="getLocation()">获取</button>
<script>
  var x=document.getElementById("demo");
  function getLocation()
  {
    if (navigator.geolocation)
    {
      navigator.geolocation.watchPosition(showPosition);
    }
    else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
  function showPosition(position)
  {
    x.innerHTML="Latitude: " + position.coords.latitude +
            "<br />Longitude: " + position.coords.longitude;
  }
</script>
</body>
</html>